package Work05;


import Work04.TicktThread;

import java.util.Random;

public class Test {
    public static void main(String[] args) {
        //对象接收总票数
        TicktThread.Tickets ti = new TicktThread.Tickets(100);

        TicketThread ticketThread = new TicketThread(ti);
        //创建三个线程代表三个售票窗口
        new Thread(ticketThread, "一号窗口").start();
        new Thread(ticketThread, "二号窗口").start();
        new Thread(ticketThread, "三号窗口").start();
    }
}

class TicketThread implements Runnable{
    private TicktThread.Tickets ti;

    public TicketThread() {

    }

    public TicketThread(TicktThread.Tickets ti) {
        this.ti = ti;
    }

    //重写run方法
    @Override
    public void run() {
        //定义售出票数
        for (int i = 0; i < 100; i++) {
            Random r = new Random();
            //定义一次售票最多不超过两张
            int a = r.nextInt(2) + 1;
            try {
                ti.ticket(a);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


